//
//  ListTableViewController.swift
//  5swiftHere
//
//  Created by 杜承玖 on 2/11/15.
//  Copyright (c) 2015 redianying. All rights reserved.
//

import UIKit

class ListTableViewController: UITableViewController {
    
    var colorList = [ UIColor.whiteColor(), UIColor.greenColor(), UIColor.yellowColor(), UIColor.purpleColor(), UIColor.blueColor(), UIColor.brownColor() ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //init color list
        
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return colorList.count
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return UIScreen.mainScreen().bounds.size.height / CGFloat(colorList.count)
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
        
        cell.backgroundColor = colorList[indexPath.row]
        
        return cell
    }
    
   // sender is cell
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let targetVC = segue.destinationViewController as ViewController
        
        let cell = sender as UITableViewCell
        targetVC.color = cell.backgroundColor!
    }
    

}
